import { defineStore } from 'pinia'
import { store } from '/@/store'

import { SerialOption } from '/@/api/serialPort/model/serialPort'

interface JRLinksState {
  nowSerialPort: SerialOption | null
}

export const useJRLinksState = defineStore({
  id: 'serial-port',
  state: (): JRLinksState => ({
    nowSerialPort: null,
  }),
  getters: {
    getNowSerialPort(): SerialOption {
      return this.nowSerialPort || ({} as SerialOption)
    },
  },
  actions: {
    /**
     * Set up multilingual information and cache
     * @param info multilingual info
     */
    setNowSerialPort(serialPort: SerialOption) {
      this.nowSerialPort = serialPort
    },
    /**
     * Initialize multilingual information and load the existing configuration from the local cache
     */
    initLocale() {},
  },
})

// Need to be used outside the setup
export function useJRLinksStoreWithOut() {
  return useJRLinksState(store)
}
